{extend name="Layout/layout" /}
{block name="leftmenu"}
{include file="C/leftmenu_user" /}
{/block}

{block name="main"}
<div class="htmltitle">
	<h2>操作记录</h2>
	<div>
		<p>这里显示您所在单位曾申请过的领用记录</p>
	</div>
</div>

<div id="data_container"
	style="position: absolute; left: 15px; top: 100px; buttom: 20px; width: 160px; border-right: 1px solid #666"></div>
<div id="myForm"
	style="position: absolute; left: 190px; top: 100px; buttom: 20px;">
</div>

<div id="accObj"
	style="position: absolute; left: 470px; top: 100px; buttom: 20px; right: 10px;"></div>

<div id="myForm_tip" style="display: none;">
	<p style="color: blue; padding: 50px 50px;">点击左侧列表查看详细信息</p>
</div>
<script>
	$("#data_container").css("height",
			$(".main").height() - $(".htmltitle").height() - 30 - 10 + "px");
	//h2的margin、底部预留10
	var myList = new dhtmlXList(
			{
				container : "data_container",
				type : {
					template : "<b style='color:blue;'>#mcreate_time#</b><br/>#username#&nbsp;&nbsp;&nbsp;&nbsp;单号:#id#<br/><span style='color:#9c49f5'>#progress#</span>",
					height : 70
				},
				select: true,
			});
	var dataList = {data:{$list}};//此形式便于 myList.parse()使用
	myList.parse(dataList,"json");
	//myList.define("select",true);	//单选模式。（multiselect为多选）
	$("#myForm").html($("#myForm_tip").html());
	var myForm,evId;
	// 绑定点击 list Item 事件
	myList.attachEvent("onAfterSelect", function(id) {
		dhtmlx.message({text:id});
		var index = myList.indexById(id);
		var formData = dataList['data'][index];
		form_init(formData);	//初始化 领用申请单
		$.post("todo",{main_id:id,req:"getDetail"},function(dData){
			loadDetail(dData);	//加载 detail 内容
		});
	});

/**
 * 初始化 领用申请单
 */
function form_init(formData){
	$("#myForm").html("");
	var	formStructure = [
		{type:"fieldset",label:"领用申请单(单号："+formData['id']+")",inputWidth:"auto",list:[
      		{type:"settings",labelWidth:70,inputWidth:140},
      		{type:"block",inputWidth:"auto",blockOffset:0,offsetTop:0,list:[
				{"type":"input","name":"form_type","label":"表单分类",/*value:formData['form_type'],*/readonly:true},
				{"type":"input","name":"username","label":"建单人",/*value:formData['name'],*/readonly:true},
				{"type":"input","name":"usertel","label":"建单人电话",/*value:formData['tel'],*/readonly:true},
				{"type":"hidden","name":"from_dept","label":"向谁申请"},
				{"type":"input","name":"to_store","label":"存放地点",/*value:formData['location'],*/readonly:true},
				{"type":"input","name":"owner","label":"使用人",/*value:formData['owner'],*/readonly:true},
				{"type":"input","name":"to_dept","label":"使用单位",/*value:formData['dept'],*/readonly:true},
				{"type":"input","name":"mremarks","label":"备注",rows:3,/*value:formData['mremarks'],*/readonly:true},
				
			]},
			{type:"label",label:"审批结果"},
			{type:"block",inputWidth:"auto",blockOffset:0,offsetTop:0,list:[
				{"type":"input","name":"progress","label":"状态",readonly:true},
				{"type":"input","name":"from_store","label":"领用地点",readonly:true},
				{"type":"input","name":"mlogs","label":"操作记录",rows:5,/*value:formData['mlogs'],*/readonly:true},
			]},
		]},
	];
	myForm = null;
	myForm = new dhtmlXForm('myForm',formStructure);
	myForm.loadStruct({data: formData});	//加载领用申请单数据
	formStructure = null;
}
/**
 * 加载deteil内容
 */
function loadDetail(dData){
	$("#accObj").html("");
	var myAcc = new dhtmlXAccordion({
		parent: "accObj",
		multi_mode: true,
	});
	var id = 0,idd;
	var accForm = [];
	for(var i=0;i<dData.length;i++){
		addAcc(dData);
	}
	function addAcc(dData){
		id ++;
		myAcc.addItem("a"+id,"领用物品"+id,true,165);
		var addStructure = [
			{type:"block",inputWidth:"auto",blockOffset:"5",offsetTop:0,list:[
				{type:"settings",labelWidth:50,inputWidth:140},
				{type:"block",inputWidth:"auto",blockOffset:"-",list:[
 					{"type":"input","name":"name"+id,"label":"名称",readonly:true},
 					{"type":"input","name":"type"+id,"label":"型号",readonly:true},
				]},
 				{type:"newcolumn"},
 				{type:"block",inputWidth:"auto",blockOffset:"-",list:[
	 				{"type":"input","name":"units"+id,"label":"计量单位",readonly:true},
						{"type":"input","name":"maker"+id,"label":"制造厂商",readonly:true},
				]},
				{type:"newcolumn"},
				{type:"block",inputWidth:"auto",blockOffset:"-",list:[
 					{"type":"input","name":"count"+id,"label":"数量",readonly:true},
					{"type":"input","name":"dusage"+id,"label":"用途",readonly:true},
				]},
			]},
			{type:"block",inputWidth:"auto",blockOffset:"25",offsetTop:0,list:[
				{type:"settings",labelWidth:50,inputWidth:450},
				{"type":"input","name":"dremarks"+id,"label":"备注",rows:2,readonly:true},
			]},
		];
		accForm[id] = myAcc.cells("a"+id).attachForm(addStructure);		
		for(v in dData[id-1]){
			// 处理dData (name/type等变为name1/type1等)
			dData[id-1][v+id]=dData[id-1][v];
		}
		accForm[id].loadStruct({data: dData[id-1]});
		dData=null;
	}
}
</script>
{/block}




